﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace BtoBSWT315.User
{
    public partial class MessageDetail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (Session["user"] == null)
            {
                Response.Redirect("../Default.aspx");
            }

            if (!IsPostBack)
            {

                if (Request.QueryString["id"] == null || Request.QueryString["id"].ToString() == String.Empty)
                {
                    Response.Write("错误!! 参数出了问题..");
                    Response.End();
                }

                string strID = Request.QueryString["id"].ToString();
                //ViewState["ID"]

                alterState(strID); //改变信息 状态
                getData(strID); //获取信息 内容
            }
        }

        private void alterState(string strID) //改变信息 状态
        {
            string mySql = "update messages set MState=1 where MState<>1 and info_id=" + strID;
            Admin.Admin_ClassDb mydb = new Admin.Admin_ClassDb();
            mydb.GetNonResult(mySql);

        }


        private void getData(string strID) //获取信息 内容
        {
            string mySql = "select * from messages where info_id=" + strID;
            Admin.Admin_ClassDb mydb = new Admin.Admin_ClassDb();
            DataTable dataTable = mydb.GetTables(mySql);

            if (dataTable != null && dataTable.Rows.Count > 0)
            {
                foreach (DataRow row in dataTable.Rows)
                {
                    lblUName.Text = row["linkman"].ToString();
                    lblUPhone.Text = row["phone"].ToString();
                    string strUEmail = row["mail"].ToString();
                    lblUEmail.Text = "<a href='mailto:" + strUEmail + "'>" + strUEmail + "</a>";
                    lblMTitle.Text = row["title"].ToString();
                    txtMContent.Text = row["content"].ToString();
                    lblDate.Text =String.Format(row["dateandtime"].ToString(),"{0:yyyy-MM-dd}");
                }
            }
            else
            {
                Response.Write("没有这条信息");
                Response.End();
            }
        }

        #region Web 窗体设计器生成的代码
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {

        }
        #endregion
    }
}